package com.api.oa.services.impl;

import cn.hutool.core.date.DateUtil;
import com.api.oa.mapper.YQCheckInsMapper;
import com.api.oa.model.entity.YQCheckIns;
import com.api.oa.model.vo.OaOrgTreeVO;
import com.api.oa.services.YQCheckInsService;
import com.api.oa.utils.LocalRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;


@Service
public class YQCheckInsServiceImpl implements YQCheckInsService {

    @Autowired
    private YQCheckInsMapper mapper;
    @Autowired
    private LocalRedis localRedis;


    @Override
    public Integer add(YQCheckIns entity) {
        entity.setCreatedAt(DateUtil.date());
        return mapper.insert(entity);
    }

    @Override
    public void remove(Long id) {
        mapper.delete(id);
    }

    @Override
    public Integer update(YQCheckIns entity) {
        return mapper.update(entity);
    }

    @Override
    public PageInfo<YQCheckIns> list(Long pid, Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        PageHelper.orderBy("createdAt desc");
        return new PageInfo<>(mapper.list(pid));
    }

    @Override
    public YQCheckIns one(Long id) {
        return mapper.findOne(id);
    }

    @Override
    public List<YQCheckIns> all() {

        Object o = localRedis.get("YQCheckInsService.all");
        if (o == null) {
            List<YQCheckIns> all = mapper.all();
            localRedis.set("YQCheckInsService.all", all, 3600 * 24);
            return all;
        }
        return (List<YQCheckIns> ) o;
    }


}
